import 'package:my_app/features/article/domain/article.dart';
import 'package:my_app/features/article/domain/article_repository.dart';
import 'package:signals/signals_flutter.dart';

class ArticleViewModel {
  final ArticleRepository _repo;
  ArticleViewModel(this._repo);

  final articles = asyncSignal<List<Article>>(AsyncState.data([]));

  Future<void> load() async {
    articles.value = AsyncState.loading();
    try {
      final data = await _repo.fetchArticles();
      articles.value = AsyncState.data(data);
    } catch (e) {
      articles.value = AsyncState.error(e);
    }
  }
}